package com.right.health.app.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;

import com.right.health.app.R;
import com.right.health.app.widget.wheelView.adapter.NumericWheelAdapter;
import com.right.health.app.widget.wheelView.view.WheelView;

/*
 * Created by hopeliao on 2019-10-13
 *
 */
public class TimeBottomPickerDialog extends BaseBottomSheetDialog implements View.OnClickListener {

    private WheelView mHourView;

    private WheelView mMinuteView;


    private OnConfirmListener mConfirmListener;

    public void setConfirmListener(OnConfirmListener listener) {
        this.mConfirmListener = listener;
    }

    public TimeBottomPickerDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.dialog_time_picker;
    }

    @Override
    protected void findViews() {
        super.findViews();
        mHourView = (WheelView) findViewById(R.id.hour_view);
        mMinuteView = (WheelView) findViewById(R.id.minute_view);

        findViewById(R.id.view_placeholder).setOnClickListener(this);
        findViewById(R.id.tv_cancel).setOnClickListener(this);
        findViewById(R.id.tv_yes).setOnClickListener(this);

        mHourView.setAdapter(new NumericWheelAdapter(1, 24));
        mHourView.setCyclic(false);

        mMinuteView.setCyclic(false);
        mMinuteView.setAdapter(new NumericWheelAdapter(1, 60));
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.view_placeholder || v.getId() == R.id.tv_cancel) {
            dismiss();
        } else if(v.getId() == R.id.tv_yes) {
            if(mConfirmListener != null) {
                mConfirmListener.onConfirm(mTag, mHourView.getCurrentItem() + 1, mMinuteView.getCurrentItem() + 1);
            }
        }
    }

    public interface OnConfirmListener {
        void onConfirm(Object tag, int chooseHour, int chooseMin);
    }
}
